package com.example.ffepeg.ffe;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class VideoTestAdd {
    public static void main(String[] args) {
        // FFmpeg命令及参数
        String inputFilePath = "src/main/resources/out/video.mp4";
        String outputFilePath = "src/main/resources/out/outputVideoBBB.mp4";

        // 创建ProcessBuilder对象并设置命令
        String[] command = {
                "ffmpeg",
                "-i", inputFilePath,                  // 输入文件
                "-b:v", "5000k",                    // 设置视频比特率为5000 kbps
                "-c:v", "libx264",                  // 使用H.264编解码器
                "-crf", "1",                       // 设置CRF值为18 (高质量)
                "-preset", "slow",                  // 使用慢速预设 (更好的压缩)
                outputFilePath                        // 输出文件
        };
        ProcessBuilder builder = new ProcessBuilder(command);
        try {
            builder.redirectErrorStream(true);
            Process process = builder.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            int code = process.waitFor();
            System.out.println("Ffmpeg退出代码编号为: "+ code);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
